package PackagesTests;

import java.io.IOException;
import Utils.ByteTree;
import Utils.TypeConvertionUtils;

/**
 * A tester class for Byte Tree class.
 * 
 * @author nirhagin
 *
 */
public class ByteTreeTest {
	
	        /**
	         * @param args
	         * @throws IOException 
	         */
	        public static void main(String[] args) throws IOException {
	                
	                ByteTree bt = null;
	                bt = testArrayByteTree();
	                methodsTester(bt);
	                bt = testStringByteTree();
	                methodsTester(bt);
	                testStringByteTree();   
	                byteTreeTest();
	        }

	       
	        
	        public static ByteTree testArrayByteTree() throws IOException{
	                byte[] byteArr = {(byte) 0, (byte)0, (byte)0, (byte)0,(byte)2,
	                                (byte)0,(byte)0,(byte)0,(byte)0,(byte)2,
	                                        (byte)1,(byte)0,(byte)0,(byte)0,(byte)4,(byte)70,(byte)71,(byte)72,(byte)73,
	                                        (byte)1,(byte)0,(byte)0,(byte)0,(byte)2,(byte)3,(byte)225,
	                                (byte)1,(byte)0,(byte)0,(byte)0,(byte)2,(byte)1,(byte)1};
	                ByteTree bt = new ByteTree(byteArr);
	                return bt;
	        }
	        
	        public static void methodsTester(ByteTree bt){
	                System.out.println("printing parameters of bt");
	                System.out.println("is bt leaf? " + bt.isLeaf());
	                System.out.println("how many children? " + bt.getAmountOfDirectChildren());
	                int i = bt.getAmountOfDirectChildren();
	                ByteTree btArray[] = new ByteTree[i];
	                for (int j=0;j<i;j++){
	                        btArray[j] = bt.getTheNChild(j);
	                        System.out.println("is child " + j + " a leaf? "  + btArray[j].isLeaf());
	                        System.out.println("how many children for child " +j+ "?" + btArray[j].getAmountOfDirectChildren());
	                        System.out.println("print string of child " + j + " " + btArray[j].getString());
	                        System.out.println("print number of child "  + j + " " + btArray[j].getBigNum());
	                }
	        }
	        

	        
	        public static void byteTreeTest() throws IOException{
	                byte[] data = {(byte)70,(byte)71,(byte)72,(byte)73};
	                ByteTree node = ByteTree.generateEmptyNode();
	                ByteTree child = ByteTree.generateNewLeaf(data);
	                ByteTree newNode = node;
	                newNode.addChild(child);
	                newNode.addChild(child);
	                System.out.println(newNode.isLeaf());
	                System.out.println(newNode.getAmountOfDirectChildren());
	                System.out.println(newNode.getSizeOfData());
	                System.out.println(newNode.getTheNChild(0).isLeaf());
	                System.out.println(newNode.getTheNChild(0).getSizeOfData());
	                System.out.println(newNode.getTheNChild(0).getString());
	                System.out.println(newNode.getTheNChild(1).isLeaf());
	                System.out.println(newNode.getTheNChild(1).getSizeOfData());
	                System.out.println(newNode.getTheNChild(1).getString());
	                ByteTree child2 = ByteTree.generateNewLeaf(TypeConvertionUtils.stringToByteArr("BOLI"));
	                ByteTree newTree = ByteTree.generateEmptyNode();
	                ByteTree multiChilds = newTree;
	                newTree.addMultChildren(child2,child);
	                System.out.println("multiChilds:\n" + multiChilds);
	                System.out.println(multiChilds.isLeaf());
	                System.out.println(multiChilds.getAmountOfDirectChildren());
	                System.out.println(multiChilds.getSizeOfData());
	                System.out.println(multiChilds.getTheNChild(0).isLeaf());
	                System.out.println(multiChilds.getTheNChild(0).getSizeOfData());
	                System.out.println(multiChilds.getTheNChild(0).getString());
	                System.out.println(multiChilds.getTheNChild(1).isLeaf());
	                System.out.println(multiChilds.getTheNChild(1).getSizeOfData());
	                System.out.println(multiChilds.getTheNChild(1).getString());
	        }
	        
	        public static ByteTree testStringByteTree() throws IOException{
                String str = "0000000002010000001c766572696669636174756d2e61726974686d2e4d6f645047726f757000000000040100000041014354c848a190b7b5fbddcd07bed36e59af5a50cc5966b202bba0959ccc42061a2f468f87fa436451bd48d5cb333c0bb0aca763193e70c725495455a99939276f010000004100a1aa642450c85bdafdeee683df69b72cd7ad28662cb359015dd04ace6621030d17a347c3fd21b228dea46ae5999e05d85653b18c9f386392a4aa2ad4cc9c93b701000000410132027413c1464af9b3ebe05f40059902857843365887f3e084e973dfd3da198697724ac422dfce4728c2baa07760b5eae2d709bd7ff4f79d4e71fc9c2d37e267010000000400000001";
                ByteTree bt = new ByteTree(str);
                return bt;
        }
	
}
